@extends( 'layout.home' )
@section( 'content' )
    <!--面包屑导航 开始-->
    <div class="crumb_warp">
        <!--<i class="fa fa-bell"></i> 欢迎使用登陆网站后台，建站的首选工具。-->
        <i class="fa fa-home"></i> <a href="{{url( 'info' )}}">首页</a> &raquo; 月租管理 &raquo; 月租办理
    </div>
    <!--面包屑导航 结束-->

    <!--结果集标题与导航组件 开始-->
    <div class="result_wrap">

        <div class="result_content">
            <div class="short_wrap">
            </div>
        </div>
    </div>
    <!--结果集标题与导航组件 结束-->

    <div class="result_wrap">
        <form>
            {{csrf_field()}}
            <table class="add_tab">
                <tbody>
                <tr>
                    <th><i class="require">*</i>车牌号：</th>
                    <td>
                        <select id="carcity">
                            <option value="">请选择</option>
                            @foreach($carcity as $v)
                                <option value="{{$v['code']}}">{{$v['code']}}</option>
                            @endforeach
                        </select>
                        <span style="font-weight: bold;margin-right: 10px;">·</span>
                        <input type="text" name="plate_num">
                        <span><i class="fa fa-exclamation-circle yellow"></i>车牌号必须填写</span>
                    </td>
                </tr>
                <tr>
                    <th><i class="require">*</i>车类型：</th>
                    <td>
                        <input type="radio"  name="plate_type" value="1">小车
                        <input type="radio"  name="plate_type" value="2" style="margin-left: 20px;">货车/客车
                    </td>
                </tr>
                <tr>
                    <th><i class="require">*</i>车主姓名：</th>
                    <td>
                        <input type="text" name="carname">
                    </td>
                </tr>
                <tr>
                    <th><i class="require">*</i>手机号：</th>
                    <td>
                        <input type="text" name="carphone">
                    </td>
                </tr>
                <tr>
                    <th><i class="require">*</i>办理时长：</th>
                    <td>
                        <select id="duration">
                            <option value="0">请选择</option>
                            @for($i = 1; $i <= 36; $i++)
                            <option value="{{$i}}">{{$i}}个月</option>
                            @endfor
                        </select>
                         （单月租费：{{config('charge.MONTHLY')}}元/月/辆）
                    </td>
                </tr>
                <tr>
                    <th><i class="require">*</i>选择车位：</th>
                    <td>
                        <span class="piddiv" style="color: #000;font-size: 14px;"></span>
                        &nbsp;<input type="button" value="请选择" id="getparkingspace"  onclick="pop()">
                        <input type="hidden" id="parkingspace_no" value="" >

                    </td>
                </tr>
                <tr>
                    <th></th>
                    <td>
                        <input type="button" value="办理" id="submit">
                        <input type="button" class="back" onclick="history.go(-1)" value="返回">
                    </td>
                </tr>

                </tbody>
            </table>
        </form>
    </div>
    <script src="https://cdn.bootcss.com/layer/3.1.0/layer.js"></script>
    <script>
        function pop(){
            layer.open({
                type: 2,
                title:'请选择车位',
                area: ['800px', '500px'],
                fixed: false, //不固定
                maxmin: true,
                content: "{{url('getparkingspace')}}"
            });
        }

        $("#submit").click(function(){//点击提交
            var carcity = $("#carcity").val();
            var plate_num = $("input[name='plate_num']").val();
            var plate_type = $("input[name='plate_type']:checked").val();
            var carname = $("input[name='carname']").val();
            var carphone = $("input[name='carphone']").val();
            var duration = $("#duration").val();
            var parkingspace_no = $("#parkingspace_no").val();
            // if(!carcity||!plate_num||!plate_type||!carname||!carphone||duration==0||!parkingspace_no){
            //     layer.msg('请填写完整！');
            //     return false;
            // }
            var totle = duration * {{config('charge.MONTHLY')}};
            var str = "应收费用" + totle + "元，请核实！";
            layer.confirm(str, {btn: ['确定', '取消'], title: "提示"}, function () {
                $.post('{{url('rent')}}',{
                    '_token':"{{csrf_token()}}",
                    carcity:carcity,
                    plate_num:plate_num,
                    plate_type:plate_type,
                    carname:carname,
                    carphone:carphone,
                    duration:duration,
                    parkingspace_no:parkingspace_no,
                },function(data){
                    if(data.code){
                        layer.msg(data.msg);
                        setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
                            window.location.reload();//页面刷新
                        },2000);
                    }else{
                        layer.msg(data.msg);
                    }
                });
            });

        });
    </script>
@endsection
